import Vue from 'vue'
import Router from 'vue-router'
const Login = () => import('./components/Login.vue')
const Home = () => import('./components/Home.vue')
const Welcome = () => import('./components/Welcome.vue')
const Users = () => import('./components/user/Users.vue')
const UserInfo = () => import('./components/user/UserInfo.vue')

const Labels = () => import('./components/label/Labels.vue')
const LabelsMap = () => import('./components/label/Labels-map.vue')
const AddLabels = () => import('./components/label/AddLabels.vue')

const Issues = () => import('./components/issue/Issues.vue')
const Feedbacks = () => import('./components/feedback/Feedbacks.vue')
const Feedtypes = () => import('./components/feedback/Feedtypes.vue')
const Contacts = () => import('./components/us/Contactus.vue')
const Aboutus = () => import('./components/us/Aboutus.vue')
const Ini = () => import('./components/ini/ini.vue')
const Param = () => import('./components/param/Param.vue')
const ScoreParam = () => import('./components/param/ScoreParam.vue')
const AccParam = () => import('./components/param/AccParam.vue')
const StaParam = () => import('./components/param/StationarityParam.vue')
const RoadParam = () => import('./components/param/RoadParam.vue')
const TurnParam = () => import('./components/param/TurnParam.vue')

const Message = () => import('./components/message/message.vue')
const NewMessage = () => import('./components/message/newmessage.vue')
const Statistic = () => import('./components/statistic/statistic.vue')
const Score = () => import('./components/score/score.vue')
const Form = () => import('./components/statistic/form.vue')
const Privacy = () => import('./components/privacyPolicy.vue')

const Admin = () =>import('./components/auth/Admin.vue')
const AddAdmin = () => import('./components/auth/Add.vue')
const AdminInfo = () => import('./components/auth/AdminInfo.vue')
const Role = () => import('./components/auth/Role.vue')
const AddRole = () => import('./components/auth/NewRole.vue')
const EditRole = () => import('./components/auth/EditRole.vue')
const Own = () => import('./components/Own.vue')



Vue.use(Router)

const router = new Router({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/users', component: Users },
        { path: '/userinfo', component: UserInfo},

        { path:'/admin', component: Admin},
        { path:'/add', component: AddAdmin},
        { path:'/admininfo', component: AdminInfo},
        { path:'/role', component: Role},
        { path:'/addrole', component: AddRole},
        { path:'/editrole', component: EditRole},
        { path:'/own', component: Own},
        

        { path: '/labels', component: Labels },
        { path: '/labels', component: Labels },
        { path: '/labels-map', component: LabelsMap },
        { path: '/addlabels', component: AddLabels },

        { path: '/issues', component: Issues },
        { path: '/feedbacks', component: Feedbacks },
        { path: '/feedtypes', component: Feedtypes },
        { path: '/contactus', component: Contacts },
        { path: '/aboutus', component: Aboutus },
        { path: '/ini', component: Ini },
        { path: '/params', component: Param },
        { path: '/accparams', component: AccParam },
        { path: '/scoreparams', component: ScoreParam },
        { path: '/staparams', component: StaParam },
        { path: '/roadparams', component: RoadParam },
        { path: '/turnparams', component: TurnParam },
        { path: '/messages', component: Message },
        { path: '/newmessages', component: NewMessage },
        { path: '/statistic', component: Statistic },
        { path: '/score', component: Score },
        { path: '/form', component: Form },
        { path: '/privacy', component: Privacy }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router
